package com.csu.letaobackend.controllerM;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.csu.letaobackend.bean.Coupon;
import com.csu.letaobackend.bean.Shopcoupon;
import com.csu.letaobackend.commom.CommonResponse;
import com.csu.letaobackend.serviceM.CouponMService;
import com.csu.letaobackend.vo.CouponVO;
import com.csu.letaobackend.vo.ShopcouponVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@CrossOrigin
@RequestMapping("/admin/coupon")
public class CouponMController {

      @Autowired
      CouponMService couponMService;

      @GetMapping("/coupons/query/pages/{pagesize}/{pageid}")
      @ResponseBody
      CommonResponse<IPage<ShopcouponVO>> getAllCoupons(@PathVariable int pageid, @PathVariable int pagesize) {
            return couponMService.getAllShopcoupons(pageid, pagesize);
      }

      @GetMapping("/{fullminus}/{shopname}/coupons/query/pages/{pagesize}/{pageid}")
      @ResponseBody
      CommonResponse<IPage<ShopcouponVO>> searchCoupons(@PathVariable double fullminus,
                                                        @PathVariable String shopname, @PathVariable int pageid, @PathVariable int pagesize) {
            return couponMService.searchShopcoupons(fullminus, shopname, pageid, pagesize);
      }

      @PostMapping("/coupons")
      @ResponseBody
      CommonResponse addCoupon(@RequestBody Shopcoupon shopcoupon) {

            return couponMService.addShopcoupon(shopcoupon);
      }

      @DeleteMapping("/{couponid}")
      @ResponseBody
      CommonResponse deleteCoupon(@PathVariable  int couponid) {
            return couponMService.deleteShopcoupon(couponid);
      }

      @PutMapping("/{couponid}")
      @ResponseBody
      CommonResponse updateCoupon(@RequestBody Shopcoupon shopcoupon,@PathVariable  int couponid) {
            shopcoupon.setCouponid(couponid);
            return couponMService.updateShopcoupon(shopcoupon);
      }
}
